package com.hgh.wallet_demo.Controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hgh.wallet_demo.Common.R;
import com.hgh.wallet_demo.Service.UserWalletService;
import com.hgh.wallet_demo.entity.UserWalletEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("userMallet")
public class UserWalletController {
    @Autowired
    private UserWalletService userWalletService;

    /**
     * 查询用户钱包余额
     * @param userId
     * @return
     */
    @RequestMapping("/amount")
    public R getAmount(@RequestParam("userId") Long userId){
        UserWalletEntity user = userWalletService.getOne(new QueryWrapper<UserWalletEntity>().eq("user_id", userId));
        BigDecimal walletAmount = user.getWalletAmount();
        return R.ok().put("walletAmount",walletAmount);
    }
}
